package com.itheima.shop.aop;

import com.itheima.shop.user.SessionThreadLocal;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: design
 * @description:
 * @author: zhanghz001
 * @create: 2020-12-15 09:49
 **/
@Component
@Aspect
@Slf4j
public class LogAspect {
    @Autowired
    private SessionThreadLocal sessionThreadLocal;
    
    @Pointcut(value = "execution(int com.itheima.shop.service.*Service+.*(..))")
    public void pt() {
        
    }
    
    @SneakyThrows
    @Before(value = "pt()")
    public void share005Before(JoinPoint joinPoint) {
        //名称
        String methodName = joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName();
        log.info("用户[" + sessionThreadLocal.get().toString() + "]访问" + methodName);
    }
}
